package com.example.androidlearning.sy5;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import com.example.androidlearning.R;

public class MyPlane extends View {
    Bitmap plane;
    public float currentX;
    public float currentY;
    public MyPlane(Context context, AttributeSet set){
        super(context,set);
        plane = BitmapFactory.decodeResource(context.getResources(), R.mipmap.little_plane);
        setFocusable(true);
    }
    @Override
    public void onDraw(Canvas canvas){
        super.onDraw(canvas);
        Paint p = new Paint();
        p.setColor(Color.BLUE);
        canvas.drawBitmap(plane,currentX,currentY,p);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
            this.currentX = event.getX();
            this.currentY = event.getY();

            this.invalidate();
            return true;
    }
}
